package huaabdelmartin_stage2;

import java.util.*;

public class TheBrain extends Observable {//this class will be a 'Subject'

	//instance variables
	private LinkedList<Car> taxisCollection = new LinkedList<Car>();
	private LinkedList<PassengerGroup> passengerGroupCollection= new LinkedList<PassengerGroup>();
	private ArrayList<Worker> workerList = new ArrayList<Worker>();
	private ArrayList<Thread> workerThreads = new ArrayList<Thread>();
	
	//constructor
	public TheBrain(LinkedList<Car> taxisCollection, LinkedList<PassengerGroup> passengerGroupCollection) {
		
		this.taxisCollection = taxisCollection;
		this.passengerGroupCollection = passengerGroupCollection;
	}
	
	//getters and setters
	public LinkedList<Car> getTaxisCollection() {
		return taxisCollection;
	}
	public void setTaxisCollection(LinkedList<Car> taxisCollection) {
		this.taxisCollection = taxisCollection;
	}
	public LinkedList<PassengerGroup> getPassengerGroupCollection() {
		return passengerGroupCollection;
	}
	public void setPassengerGroupCollection(
			LinkedList<PassengerGroup> passengerGroupCollection) {
		this.passengerGroupCollection = passengerGroupCollection;
	}
	
	public void updateObservers(){
		setChanged();//only including in this method, so it doesn't get called getNextTaxi() too....
		notifyObservers();
    	clearChanged();
	}
	
	public synchronized Car getNextTaxi(){
		Car currentTaxi = taxisCollection.getFirst();
		taxisCollection.removeFirst();
		//updateObservers();
		return currentTaxi;
	}
		 
	public synchronized PassengerGroup getNextPG(){
		PassengerGroup currentPG = passengerGroupCollection.getFirst();
		passengerGroupCollection.removeFirst();
		//updateObservers();
		return currentPG;
	}
	
	public void addWorker( Worker w ){
		workerList.add(w);
	}
			 
	public void addWorkerThread(Thread t){
		workerThreads.add(t);
	}
	
	public ArrayList<Worker> getWorkerList() {
		return workerList;
	}

	public void setWorkerList(ArrayList<Worker> workerList) {
		this.workerList = workerList;
	}

	public ArrayList<Thread> getWorkerThreads() {
		return workerThreads;
	}

	public void setWorkerThreads(ArrayList<Thread> workerThreads) {
		this.workerThreads = workerThreads;
	}

	public boolean moreTaxis(){
		if( taxisCollection.isEmpty() ){
			return false;
		}
		return true;
	}

	public boolean morePGs(){
		if( passengerGroupCollection.isEmpty() ){
			return false;
		}
		return true;
	}
	
	public boolean hasMoreTaxis()
	{
		if(taxisCollection.size() > 0){
			return true;
		}
		
		return false;
	}
	
	public boolean hasMorePGs()
	{
		if(passengerGroupCollection.size() > 0){
			return true;
		}
		
		return false;
	}	 

}
